package com.hdax.dm.controller;

import com.hdax.dm.MainApplication;
import com.hdax.dm.base.Image;
import com.hdax.dm.dto.IndexNavDto;
import com.hdax.dm.exceptions.DmException;
import com.hdax.dm.feign.ImageFeign;
import com.hdax.dm.item.Item;
import com.hdax.dm.item.ItemType;
import com.hdax.dm.service.ItemService;
import com.hdax.dm.service.ItemTypeService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtils;
import org.checkerframework.checker.regex.qual.PolyRegex;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(path = "/item")
public class IndexNavController {

    @Autowired
    private ItemTypeService itemTypeService;

    @Autowired
    private ItemService itemService;

    /**
     * 首页横向导航数据查询
     */
    @PostMapping(path = "/index/nav")
    public CommonResponse<List<IndexNavDto>> nav(){
        return itemTypeService.navs();
    }

    @PostMapping(path = "/index/lineNav")
    public CommonResponse<List<ItemType>> lineNav(){
        return ResponseUtils.returnSuccess(itemTypeService.linenavs(0L));
    }

    /**
     * 今日推荐
     */
    @PostMapping(path = "/index/recommend")
    public CommonResponse<List<IndexNavDto.HotItems>> recommend(){
        return itemService.recommend();
    }

    /**
     * 即将开售
     */
    @PostMapping(path = "/index/sell")
    public CommonResponse<List<IndexNavDto.HotItems>> sell(){
        return itemService.sellItems();
    }


    /**
     * 楼层展示
     */
        @PostMapping(path = "/index/floor")
    public CommonResponse floor(){

        return itemService.Floors();
    }


    /**
     * 分类排行数据获取
     */
    @PostMapping(path = "/index/seniority")
    public CommonResponse seniority(@RequestBody Map<String,Long> map){
        Long itemTypeId = map.get("itemTypeId");
        return itemService.senioritys(itemTypeId);
    }


    /**
     * 本类异常抛出都会进入改方法进行统一处理
     */
    @ExceptionHandler
    public CommonResponse<String> exceptionHandler(DmException e){
        return ResponseUtils.returnFail(e);
    }
}
